﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Mvc;

    using MarketPulse.BusinessLogic.Common;
    using MarketPulse.Web.Helpers;

#endregion

namespace MUM.Controllers
{
    [HandleError]
    public class HomeController : SecurityController
    {
        #region Member Variables

            /// <summary>
            /// String used to hold the view path to use for returning from an action (when there is more than one view depending on logic)
            /// </summary>
            private string mViewPath;

            private const string constErrorMessage = "Ooops! I'm afraid an unforseen error occurred. Please report this error, along with a detailed description of what you were doing, to the IT department.";

        #endregion

        //
        // GET: /Home/
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// Methos used to set up the search form based on the BusienssObjectGUID supplied
        /// </summary>
        /// <returns>An action result object</returns>
        [AcceptVerbs(HttpVerbs.Post)]
        public PartialViewResult Search(Guid businessObjectGuid)
        {
            PartialViewResult result = null;
            try
            {
                switch (businessObjectGuid.ToString().ToUpper())
                {
                        //TODO refactor to use an enumeration for BusinessObjectType loaded from the db
                    case "C987812D-02FD-4B93-8EA7-72019814D8B3":
                        //TODO refactor to a generic search criteria object
                        SessionManager.AssignmentSearchCriteria = null;
                        SessionManager.AvailableCountries = CountryInfoList.GetAll();
                        ViewBag.CountryInfoList = SessionManager.AvailableCountries;
                        result = PartialView("~/Views/Assignment/Partials/_Search.cshtml");
                        break;
                    default:
                        ViewBag.Message = constErrorMessage;
                        result = PartialView("~/Views/Shared/Partials/_ModalErrorContent.cshtml");
                        break;
                }
            }
            catch (Exception ex)
            {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.Append("Exception experienced whilst processing the 'Search' action of the 'Home' Controller for Business Object: [");
                errorMessage.Append(businessObjectGuid);
                errorMessage.Append("]");
                mLog.Error(errorMessage.ToString(), ex);
                ViewBag.Message = constErrorMessage;
            }
            return result;
        }

        ///// <summary>
        ///// Method used to handle a post to the Search action for this controller
        ///// </summary>
        ///// <returns>An action result object</returns>
        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult GetResults(FormCollection form)
        //{
        //    AssignmentSearchCriteria criteria;
        //    try
        //    {
        //        if (SessionManager.AssignmentSearchCriteria != null)
        //        {
        //            criteria = SessionManager.AssignmentSearchCriteria;
        //        }
        //        else
        //        {
        //            criteria = new AssignmentSearchCriteria(null, Guid.Parse(form["country"]));

        //            SessionManager.AssignmentSearchCriteria = criteria;
        //        }
        //        GetAssignmentSearchResults(criteria);
        //    }
        //    catch (Exception ex)
        //    {
        //        mLog.Error("Exception experienced whilst processing the 'List' action of the 'Assignment' Controller", ex);
        //        ViewBag.Message = constErrorMessage;
        //        RedirectToAction("Index", "Home");
        //        //mViewPath = "~/Views/Home";
        //    }
        //    return View(mViewPath);
        //}

    }
}
